package com.ctshk.task.worker.processors;

import com.ctshk.common.dto.Result;
import com.ctshk.rpc.tour.service.ISeriesTripAppService;
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
import com.github.kfcfans.powerjob.worker.core.processor.TaskContext;
import com.github.kfcfans.powerjob.worker.core.processor.sdk.BasicProcessor;
import com.github.kfcfans.powerjob.worker.log.OmsLogger;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * <p>
 *  定时刷新订单数据到ES
 * </p>
 *
 * @author lys
 * @date 2021/5/25
 */
@Slf4j
@Component
public class TourCacheUpdateProcessor implements BasicProcessor {

    @DubboReference
    private ISeriesTripAppService iSeriesTripAppService;

    @Override
    public ProcessResult process(TaskContext context) throws Exception {
        OmsLogger omsLogger = context.getOmsLogger();
        Result result = iSeriesTripAppService.updateTripCache(null);
        if (!result.isSuccess()) {
            omsLogger.error("旅行团缓存更新失败");
        } else {
            omsLogger.info("旅行团缓存更新成功");
        }
        // 根据控制台参数判断是否成功
        boolean success = !"failed".equals(context.getJobParams());
        omsLogger.info("TourCacheUpdateProcessor finished process,success: .", success);
        return new ProcessResult(success, context + ": " + success);
    }
}
